package com.qfedu.edu.config;

import com.google.common.base.Predicates;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author 32632
 * @date Created in 2024/9/18 16:30
 * @modified By  32632 in 2024/9/18 16:30
 * @description AddDescriptionHere
 */
@SpringBootConfiguration
@EnableSwagger2         //使能swagger
@ConditionalOnProperty(name = "framework.config.swagger",havingValue = "true")
public class SwaggerConfig {

    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("iot")
                .apiInfo(apiInfo())
                .select()              //所有选中的位置都要生成接口文档
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))  //如果地址是 /admin开头的所有路径不生成文档
                .paths(Predicates.not(PathSelectors.regex("/error.*")))  //如果地址是以error开头那么也不生成稳当
                .build();
    }

    public ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("智慧物联云平台接口文档")
                .description("本文档主要使用于智慧物联云平台和外部的交互接口")
                .version("v1.0")
                .contact(new Contact("王小晨","http://www.chenxi.com","3263298665@qq.com"))
                .build();

    }

}
